package system

import (
	systemHandler "gin-admin/handler/v2/system"
	"gin-admin/model"
	"gin-admin/repo"
	systemService "gin-admin/service/v2/system"
)

type HandlerApp struct {
	CaptchaHandler  systemHandler.CaptchaHandler
	UserHandler     systemHandler.UserHandler
	RoleHandler     systemHandler.RoleHandler
	MenuHandler     systemHandler.MenuHandler
	UserRolrHandler systemHandler.UserRoleHandler
	RoleMenuHandler systemHandler.RoleMenuHandler
}

func NewHandlerApp() *HandlerApp {
	userRepo := repo.NewRepositoryApp[model.User]()
	userService := systemService.NewUserServiceApp(userRepo)

	captchaService := systemService.NewCaptchaServiceApp()

	roleRepo := repo.NewRepositoryApp[model.Role]()
	roleService := systemService.NewRoleServiceApp(roleRepo)

	menuRepo := repo.NewRepositoryApp[model.Menu]()
	menuService := systemService.NewMenuServiceApp(menuRepo)

	userRoleRepo := repo.NewRepositoryApp[model.UserRole]()
	userRoleService := systemService.NewUserRoleServiceApp(userRepo, roleRepo, userRoleRepo)

	roleMenuRepo := repo.NewRepositoryApp[model.RoleMenu]()
	roleMenuService := systemService.NewRoleMenuServiceApp(roleRepo, menuRepo, roleMenuRepo)

	return &HandlerApp{
		CaptchaHandler:  *systemHandler.NewCaptchaHandlerApp(captchaService),
		UserHandler:     *systemHandler.NewUserHandlerApp(userService),
		RoleHandler:     *systemHandler.NewRoleHandlerApp(roleService),
		MenuHandler:     *systemHandler.NewMenuHandlerApp(menuService),
		UserRolrHandler: *systemHandler.NewUserRoleHandlerApp(userRoleService),
		RoleMenuHandler: *systemHandler.NewRoleMenuHandlerApp(roleMenuService),
	}
}
